﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Xml.Linq;

namespace PaiBanDaPing
{
    public class CustomScreenCtrlViewModel:ObservableObject
    {
        private CustomScreenModel _customScreen = new CustomScreenModel();
        private bool _isEnabled = false;
        XDocument doc = new XDocument();
        string autoupdateFile = "autoupdate.xml";

        public CustomScreenCtrlViewModel()
        {
            cm1click = new DelegateCommand(cm1Click, Cancm1Click);   //初始化delegatecommand
        }
        //DelegateCommand

        #region command1

        public ICommand cm1click { get; set; }

        public void cm1Click(object param)
        {
            CustomScreenModel sCreen = param as CustomScreenModel;
            ScreenManger.DisplayWindows[sCreen.DisplayScreen.DeviceName].DisPlay(sCreen);
            sCreen.BitMap= ImageHelper.ChangeBitmapToImageSource(ImageHelper.GetScreenBitmap(sCreen.DisplayScreen));
            doc.Root.Element("DaPing").Elements("Url").ElementAt(sCreen.index).SetValue(sCreen.Url);
            doc.Save(autoupdateFile);
        }

        private bool Cancm1Click(object param)
        {
            return true;
        }

        #endregion command1

        public CustomScreenModel CustomScreen
        {
            get
            {
                return _customScreen;
            }

            set
            {
                _customScreen = value;
                RaisePropertyChanged("CustomScreen");
            }
        }

        public bool IsEnabled
        {
            get
            {
                return _isEnabled;
            }

            set
            {
                _isEnabled = value;
                RaisePropertyChanged("IsEnabled");
            }
        }
    }
}
